﻿using Application.Dto;
using Application.IAppSrevices;
using AutoMapper;
using Domain.Entitys;
using Domain.Repositorys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.AppSrevices
{
    public class CFFKService : ICFFKService
    {
        private readonly IMapper mapper;
        private readonly ICFFKRepositoy cFFKRepositoy;

        public CFFKService(IMapper mapper, ICFFKRepositoy cFFKRepositoy)
        {
            this.mapper = mapper;
            this.cFFKRepositoy = cFFKRepositoy;
        }
        
        /// <summary>
        /// 删除1级结构表数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> CFFKDeleteAsync(CFFKDeleteDto cFFKDeleteDto)
        {
            CFFK cFFK = mapper.Map<CFFK>(cFFKDeleteDto);
            return await cFFKRepositoy.CFFKDeleteAsync(cFFK);
        }

        /// <summary>
        /// 添加1级机构表数据
        /// </summary>
        /// <param name="cFFKAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> CFFKInsertAsync(CFFKAddDto cFFKAddDto)
        {
            CFFK cFFK = mapper.Map<CFFK>(cFFKAddDto);
            //Random random = new Random();
            //int randomPart = random.Next(10000, 100000);
            //long number = 1353318900000L + randomPart;
            //cFFK.FirstKindId = number.ToString();
            return await cFFKRepositoy.CFFKInsertAsync(cFFK);
        }

        /// <summary>
        /// 分页查询1级结构表数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<List<CFFK>> CFFKSelect(int pageIndex, int pageSize)
        {
            return await cFFKRepositoy.CFFKSelect(pageIndex, pageSize);
        }

        /// <summary>
        /// 按id查询1级结构表数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<CFFK> CFFKSelectByIdAsync(int id)
        {
            return await cFFKRepositoy.CFFKSelectByIdAsync(id);
        }

        /// <summary>
        /// 按名称查询1级结构表数据
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<CFFK> CFFKSelectByName(string name)
        {
            return cFFKRepositoy.CFFKSelectByName(name);
        }

        /// <summary>
        /// 查询数据总数
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int CFFKSelectCount()
        {
            return cFFKRepositoy.CFFKSelectCount();
        }

        /// <summary>
        /// 查询全部1级结构表数据
        /// </summary>
        /// <returns></returns>
        public async Task<List<CFFK>> CFFKSelectOption()
        {
            return await cFFKRepositoy.CFFKSelectOption();
        }

        /// <summary>
        /// 修改1级结构表
        /// </summary>
        /// <param name="cFFK"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> CFFKUpdateAsync(CFFK cFFK)
        {
            return cFFKRepositoy.CFFKUpdateAsync(cFFK);
        }
    }
}
